package data

import (
	"fmt"
	"github.com/pkg/errors"
	"yizhuoyan/go-study/pdfgo/raw/objects/basicobject"
)

type Rectangle struct {
	X float64
	Y float64
	W float64
	H float64
}

func (this *Rectangle) String() string {
	return fmt.Sprintf("[x=%v,y=%v,w=%v,h=%v]", this.X, this.Y, this.W, this.H)
}

func (this *Rectangle) ParseFrom(arr *basicobject.Array) error {
	if arr.Length() != 4 {
		return errors.Errorf("长度不为4")
	}
	this.X = arr.MustGetReal(0).ValueFloat64()
	this.Y = arr.MustGetReal(1).ValueFloat64()
	this.W = arr.MustGetReal(2).ValueFloat64()
	this.H = arr.MustGetReal(3).ValueFloat64()
	return nil
}
